#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

void Insort(int* a, int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		int end = i;
		int temp = a[end + 1];
		while (end >= 0)
		{
			if (a[end] > temp)
			{
				a[end + 1] = a[end];
				end--;
			}
			else
			{
				break;
			}
		}
		a[end + 1] = temp;
	}
}

void Print(int* a, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%d  ", a[i]);
	}
}

void Swap(int* a, int* b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}

void Quicksort(int* a, int left,int right)
{
	int begin = left;
	int end = right;
	int keyi = left;
	while (left < right)
	{
		while (left < right && a[keyi] <= a[right])
		{
			right--;
		}
		while (left<right && a[keyi]>=a[left])
		{
			left++;
		}
		Swap(&a[left], &a[right]);
	}
	int meeti = left;
	Swap(&a[keyi], &a[meeti]);
	//begin,meeti-1   meeti,end
	Quicksort(a, begin, meeti-1);
	Quicksort(a, meeti + 1, end);
}
int main()
{
	int a[5] = { 5,13,534,6,25 };
	//Insort(a, 5);
	Quicksort(a,0, 4);
	Print(a, 5);
	return 0;
}